﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace DataWorks_Tools.BasicMethods
{
    public class FileComparer : IComparer
    {
        [DllImport("Shlwapi.dll", CharSet = CharSet.Unicode)]
        private static extern int StrCmpLogicalW(string param1, string param2);

        //int IComparer.Compare(object? o1, object? o2)
        //{
        //    FileInfo? fi1 = o1 as FileInfo;
        //    FileInfo? fi2 = o2 as FileInfo;
        //    if (fi1 != null && fi2 != null)
        //    {
        //        return fi1.Name.CompareTo(fi2.Name);
        //    }
        //    else
        //    {
        //        return 0;
        //    }
        //}

        //前后文件名进行比较。
        public int Compare(object? name1, object? name2)
        {
            if (null == name1 && null == name2)
            {
                return 0;
            }
            if (null == name1)
            {
                return -1;
            }
            if (null == name2)
            {
                return 1;
            }
            return StrCmpLogicalW(name1.ToString(), name2.ToString());
        }


    }
}
